<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<tpl> $NCharset </tpl>" />
<link href="<tpl> $template_dir </tpl>/home/css/supply-add.css" rel="stylesheet" type="text/css" />
<link href="<tpl> $template_dir </tpl>/home/css/hyhpub_1_0_0.css" rel="stylesheet" type="text/css" />
<tpl> include file ='../head.config.html' </tpl>
</head>
<body>
<tpl>include file ='../top.html'</tpl></div>
<div class="content">
<div class="left add-1 pub-form" style=" overflow:hidden; padding-left:0px;" >
<div class="clear"></div>
<div class="yk-lowlight request"><tpl> $langCHave </tpl><span class="yk-ostar"></span><tpl> $langSupplyMustAdd </tpl></div>
<form class="yk-validate" action="index.php?action=save" method="post" id="addsupply" name="addsupply">
<input type="hidden" name="pic_num" id="pic_num" value="0"/>
<tpl> $seride_form </tpl>
	<table  cellpadding="0" cellspacing="0">
		<tr class="yk-blocked">
    		<th valign="top">
				<div><span class="yk-ostar"></span><tpl> $langSupplyTitle </tpl><b>:</b></div>
			</th>
        	<td class="yk-err-show">
       	  		<div class="yk-validate-wrapper">
					<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';"  type="text" class="title text yk-validate-input-error" id="supplyTitle"  name="supplyTitle" maxLength=60 />
				</div>
          		<label style="display:none"  for="supplyTitle" metaDone="true" generated="true"></label>
        	</td>
    	</tr>
		<tr class="yk-blocked">
	 		<th valign="top">
				<div><span class="yk-ostar"></span><tpl> $langSupplySelClass </tpl><b>:</b></div>
			</th>

			<td class="yk-err-show">
				<div class="yk-validate-wrapper">
					<select name="cc1" id="cc1" class="title yk-validate-input-error" style="WIDTH: 180px; height:20px;">
						<option value=""></option>
							<tpl> foreach item = parent from = $ProductCateArray </tpl>
								<option value="<tpl>$parent.id</tpl>||<tpl>$parent[5]</tpl>"><tpl>$parent.name</tpl></option>
							<tpl> /foreach </tpl>
					</select>
					<select name="c2" id="c2" style="WIDTH: 110px; height:20px;" disabled="disabled">
					</select>
					<select name="c3" id="c3" style="WIDTH: 110px; height:20px;" disabled="disabled">
					</select>
					<select name="c4" id="c4" style="WIDTH: 110px; height:20px;" disabled="disabled">
					</select>
					<input type="hidden" name="class_id" id="class_id" value="<tpl> $product_id </tpl>"/>
				</div>
				<label style="display:none" for="class_id" class="wrong" metaDone="true" generated="true"></label>	

        	</td>
		</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div><tpl> $langSupplySelType </tpl><b>:</b></span></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
					<ul class="yk-fix-float">
        				<li style=" padding-left:3px; *padding-left:4px;">
							<label><input type="radio" name="radioType" value="2" checked="checked"/><tpl> $langSupplyTypeGone </tpl></label>
						</li>
						<li style=" margin-left:-3px; *margin:0px; *padding-left:5px;">
							<label><input type="radio" name="radioType" value="1" /><tpl> $langSupplyTypeQiu </tpl></label>
						</li>
					</ul>
				</div>
          	</td>
   		</tr>
    	<tr class="yk-blocked">
    		<th>
				<div><tpl> $langSupplySelQuality </tpl><b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
					<ul class="yk-fix-float">
        				<li style=" padding-left:3px; *padding-left:4px;">
							<label><input type="radio" name="radioQuality" value="1" checked="checked"/><tpl> $langSupplyQualityOne </tpl></label>
						</li>
						<li style=" margin-left:-3px; *margin:0px; *padding-left:5px;">
							<label><input type="radio" name="radioQuality" value="2" /><tpl> $langSupplyQualityTwo </tpl></label>    					</li>
					</ul>
				</div>
        	</td>
    	</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div><tpl> $langSupplyValdate </tpl><b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
       	 			<select class="title yk-validate-input-error" style=" height:20px;" name="valdate" id="valdate">
          				<option value="1" selected="selected"><tpl> $langSupplyValdateFiveDay </tpl></option>
            			<option value="2"><tpl> $langSupplyValdateHalfMonth </tpl></option>
            			<option value="3"><tpl> $langSupplyValdateOneMonth </tpl></option>
            			<option value="4"><tpl> $langSupplyValdateOneQuarter </tpl></option>
            			<option value="5"><tpl> $langSupplyValdateNone </tpl></option>
          			</select>
				</div>
        	</td>
   		</tr>
		<tr class="yk-blocked">
    		<th valign="top">
				<div><span class="yk-ostar"></span><tpl> $langSupplyPrice </tpl><b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper" style="word-spacing:4px; *word-spacing:0px;">
       	  			<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);" type="text" id="s_price" name="s_price"/>&nbsp;<tpl> $langSupplyOr </tpl> <input type="checkbox" style=" vertical-align:-3px; *vertical-align:0px; overflow:hidden;" name="s_price_face" id="s_price_face" value="1" /> <label for="s_price_face"><tpl> $langSupplyPriceToFace </tpl></label>
				</div>
          		<label style="display:none" for="s_price" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
		<tr class="yk-blocked">
    		<th valign="top">
				<div><span class="yk-ostar"></span><tpl> $langSupplyPhone </tpl><b>:</b></div>
			</th>
        	<td valign="top">
				<div class="yk-validate-wrapper">
       	  			<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);" type="text" id="phone" name="phone"  value="<tpl> $phone </tpl>"/>
				</div>
          		<label style="display:none" for="phone" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div><span class="yk-ostar"></span>Email<b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
       	  			<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);"  type="text" id="mail" name="mail"  value="<tpl> $member_info.email </tpl>"/>
				</div>
          		<label style="display:none" for="mail" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div>QQ<b>:</b></div>
			</th>
        	<td>
		 		<div class="yk-validate-wrapper">
					<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);"  type="text" id="qq"  name="qq"  value="<tpl> $member_info.QQ </tpl>"/>
				</div>
          		<label style="display:none" for="qq" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
		</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div>MSN<b>:</b></div>
			</th>
        	<td>
       	 		<div class="yk-validate-wrapper">
					<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);"  type="text" id="msn"  name="msn" value="<tpl> $member_info.MSN </tpl>"/>
		  		</div>
         		<label style="display:none" for="msn" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div>Skype<b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
       	  			<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);"  type="text" id="skype"  name="skype"   value="<tpl> $member_info.SKYPE </tpl>"/>
				</div>  
          		<label style="display:none" for="skype" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
    	<tr class="yk-blocked">
    		<th valign="top">
				<div><tpl> $langSupplyWangwang </tpl><b>:</b></div>
			</th>
        	<td>
       	  	<div class="yk-validate-wrapper">
		  		<input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#999999';" class="title text yk-validate-input-error" style="border: 1px solid rgb(153, 153, 153);"  type="text" id="wangwang"  name="wangwang"  value="<tpl> $member_info.TAOBAO </tpl>"/>
		  	</div> 
          	<label style="display:none" for="wangwang" class="wrong" metaDone="true" generated="true"></label> 
        	</td>
    	</tr>
    	<tr class="light-blue">
        	<th valign="top">
				<div><tpl> $langSupplyPicUpload </tpl><b>:</b></div>
			</th>
        	<td valign="top">
		  		<div class="yk-validate-wrapper yk-iu">
					<div class="yk-iu-fipt-ctn">
						<input name="txtPpic"  type="file" id="txtPpic"  style="line-height:-18px;" size="45"/>
			
            			<input type="button" class="input-chuan" name="buttonUpload" id="buttonUpload" value="<tpl> $langSupplyUpload </tpl>" onclick="return ajaxFileUpload();" />
		  			</div>
					<!--图片名拼字符串，中间以'|'连接-->
            		<input type="hidden" name="p_pic" id="p_pic" />
            		<div class="yk-iu-fipt-notice"><tpl> $langSupplyPicUploadRemark </tpl></div>
					<div class="yk-iu-uploaded-ctn"><ul></ul></div>
					<div id="previewImage">
						<ul id="piclist"></ul>
					</div>		
					<span id="file_pic_loading" style="display:none">
						<img src="<tpl> $template_dir </tpl>/images/loading.gif" />
					</span>
				</div>
			</td>
		</tr>
     
     	<tr class="yk-blocked">
        	<th valign="top">
				<div><tpl> $langSupplyContent </tpl><b>:</b></div>
			</th>
        	<td>
				<div class="yk-validate-wrapper">
					<textarea name="Content" id="Content"></textarea>
				</div>
            	<div class="yk-validate-bbs">
					<span class="yk-lowlight"><tpl> $langSupplyContentRemark </tpl></span>
				</div>
			</td>
		</tr>
		<tr class="yk-blocked">
			<th valign="top">
				<div><span class="yk-ostar"></span><tpl> $langSupplyCode </tpl><b>:</b></div>
			</th>
			<td>
				 <div class="yk-validate-wrapper yk-iu">
				 <div class="weibu">
				 	<ul>
            			<li class="weibu-1"><input onfocus="this.style.borderColor = '#ff6600';" onblur="this.style.borderColor = '#7f9db9';" class="title5 text" name="code" type="text" id="code" size="4" maxlength="4" /></li>
						<li  class="weibu-2"><img src="<tpl> $site_url </tpl>/classes/libraries/code.php" onclick="this.src='<tpl> $site_url </tpl>/classes/libraries/code.php?' + Math.random()" title=" <tpl> $langSupplyCodeChange </tpl> " id="codeimage" name="codeimage" style=" vertical-align:-5px;"/></li>
						<li  class="weibu-3"><a href="javascript:;" onclick="document.getElementById('codeimage').src='<tpl> $site_url </tpl>/classes/libraries/code.php?' + Math.random()"><tpl> $langSupplyCodeChange </tpl></a></li>
						<li  class="weibu-4">
							<tpl> if $is_member eq 1 </tpl> 
            					<input type="checkbox" id="anonymous" name="anonymous" value="2" />
			  					<label for="anonymous"><tpl> $langSupplyAnonymous </tpl></label>
            					<tpl> else </tpl>
			   					<tpl> $langSupplyAnonymousNoLogin </tpl>
               					<input type="hidden" id="anonymous" name="anonymous" value="2" />
            				<tpl> /if </tpl>
						</li>
					</ul>
				</div>
				<div class="code-1"  id="error_code"></div>
            	<label style="display:none" for="code" class="wrong" metaDone="true" generated="true"></label>
			</div>
      		</td>
		</tr>
	</table>
<div class="pub-divideline"></div>
<div class="pub-submit"><input  type="submit" id="addsubmit"  value="<tpl> $langSupplySave </tpl>"/></div>
</form>
</div>
<div class="right">
	<tpl> include file ='supply.right.html' </tpl>
</div> 
</div>
<div class="clear-30"></div>
<tpl> include file ='../../../../html/footer.html' </tpl>
</body>
</html>
<script language="javascript">
$(function(){
	//商品类别
	tonext('#cc1');
	//表单验证
	$("#addsupply").validate({
		
		rules: {
			class_id: {required:true},
			supplyTitle: {required:true,minlength:2,maxlength:50},
			code: {required:true,minlength:4,maxlength:4},
			phone: {required:true,maxlength:50},
			mail: {required:true,email:true,maxlength:50},
			qq: {maxlength:11},
			msn: {email:true,maxlength:50},
			skype: {maxlength:50},
			wangwang: {maxlength:50},
			s_price:{
				required:function(){
					if($('#s_price_face').attr('checked') == false){
						return true;
					}else{
						return false;
					}
				},
				number:function(){
					if($('#s_price_face').attr('checked') == false){
						return true;
					}else{
						return false;
					}
				},
				min:function(){
					if($('#s_price_face').attr('checked') == false){
						return 0.01;
					}else{
						return false;
					}
				},
				max:function(){
					if($('#s_price_face').attr('checked') == false){
						return 999999999.99;
					}else{
						return false;
					}
				}
			}
		},
		messages: {
			class_id: {required: "<tpl> $errSupplyClassIsEmtpy </tpl>"},
			supplyTitle: {required: "<tpl> $errSupplyTitleIsEmtpy </tpl>",minlength: "<tpl> $errSupplyTitleIsTooShort </tpl>",maxlength: "<tpl> $errSupplyTitleIsTooLong </tpl>"},
			code: {required: "<tpl> $errSupplyCodeIsEmpty </tpl>",minlength: "<tpl> $errSupplyCodeIsEmpty </tpl>",maxlength: "<tpl> $errSupplyCodeIsEmpty </tpl>"},
			phone: {required:'<tpl> $errSupplyPhoneIsEmpty </tpl>',maxlength: "<tpl> $errSupplyPhoneIsTooLong </tpl>"},
			mail: {required:'<tpl> $errSupplyEmailIsEmpty </tpl>',email: "<tpl> $errSupplyEmailIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyEmailIsTooLong </tpl>"},
			qq: {maxlength: "<tpl> $errSupplyQQIsTooLong </tpl>"},
			msn: {email: "<tpl> $errSupplyMSNIsWrongFormat </tpl>",maxlength: "<tpl> $errSupplyMSNIsTooLong </tpl>"},
			skype: {maxlength: "<tpl> $errSupplySkypeIsTooLong </tpl>"},
			wangwang: {maxlength: "<tpl> $errSupplyWangwangIsTooLong </tpl>"},
			s_price:{required:"<tpl> $errSupplyPriceIsEmpty </tpl>",number:"<tpl> $errSupplyPriceIsNotNumber </tpl>",min:"<tpl> $errSupplyPriceIsMin </tpl>0.01",max:"<tpl> $errSupplyPriceIsMax </tpl>999999999.99"}
		},
		errorPlacement: function(error, element) {   
			if (element.attr("name") == "code" )  {
				error.appendTo("#error_code");  
			}else {
				error.appendTo( element.parent() );  
			}
		},
		submitHandler: function() {
			document.getElementById('addsubmit').disabled;
			$.get("index.php",{action:"check_code",checkcode:$('#code').val(),random_number:Math.random()},function(data){
			if(data == '1'){
				document.getElementById('addsupply').submit();
			}else{
				alert('<tpl> $errSupplyCodeIsWrong </tpl>');
				document.getElementById('addsubmit').disabled = false;
				return false;
			}})
			return false;
		}
	});
})
function tonext(whos) {
	$(whos).change(
	function(){
		var valarray=$(this).val().split('||');
		$('#class_id').val(valarray[0]);
		if (valarray[1]=='1') {
			$(this).next().attr('disabled','true').html('<option value="" selected="selected"><tpl> $langCDataToLoading </tpl></option>');
			$.get('../../member/own_productcate.php',{action:'list',id:valarray[0]},function(data){
				DataArray = data.split("|||");var a='';for (var i = 0; i<DataArray.length-1; i++) {att=DataArray[i].split("||");id=att[0];cla=att[2];a+='<option value="'+id+'||'+cla+'">'+att[1]+((cla=='1')?' ->':'')+'</option>';};
				$(whos).next().removeAttr('disabled').html('<option value="" selected="selected"></option>'+a).nextAll().html('');
				tonext($(whos).next());
			})} else {
				$('#c4').attr('disabled','true');
				$(whos).next().html('').attr('disabled','true');
			};
	})
};

function ajaxFileUpload()
{
	$("#file_pic_loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	if($("#pic_num").val() >= 3){
		alert("<tpl> $errSupplyImageIsBeyong </tpl>:3");
		return false;
	}
	$.ajaxFileUpload
	(
		{
			url:'index.php?action=pic_add',
			secureuri:false,
			fileElementId:'txtPpic',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.type) != 'undefined')
				{
					if(data.type == '0')
					{
						alert(data.message);
					}else{
						$("#previewImage ul").append("<li>"+"<img src=<tpl> $site_url </tpl>/"+data.message+" /><br /><a href='javascript:;' onclick=ajaxFileDel(\'"+data.message+"\',this);><tpl> $errSupplyDel </tpl></a></li>");
						if($('#p_pic').val() == ''){
							$('#p_pic').val(data.message);
						}else{
							$('#p_pic').val($('#p_pic').val()+'|'+data.message);
						}
						//图片数量+1
						$("#pic_num").val(parseInt($("#pic_num").val())+1);
					}
				}
			},
			error: function (data, status, e)
			{
				alert('<tpl> $errSupplyUploadPicIsFail </tpl>');
			}
		}
	)
	return false;
}

function ajaxFileDel(pic_url,obj){
	$.ajax({
		url: "index.php",
		data: 'action=pic_del&pic_name='+pic_url,
		type:'post',
		dataType:"json",
		success: function(msg){
			if(msg.type == '0'){
				alert(msg.message);
			}else{
				$(obj).parents("li").remove();
				arr = $('#p_pic').val().split('|');
				for(i=0;i<arr.length;i++){
					if(arr[i] == pic_url){
						delete(arr[i]);
					}
				}
				$('#p_pic').val(arr.join('|'));
				$("#pic_num").val(parseInt($("#pic_num").val())-1);
			}
		}
	});
	return false;
}
</script>